#include <iostream>
#include <stdio.h>
using namespace std;
int Tower[507][507];
int main() {
    int n;
    scanf("%d", &n);
    for (int i=0; i<n; ++i) {
        for (int j=0; j<=i; ++j) scanf("%d", &Tower[i][j]);
    }
    for (int i=1; i<n; ++i) {
        Tower[i][0]=Tower[i-1][0]+Tower[i][0];
        Tower[i][i]=Tower[i-1][i-1]+Tower[i][i];
        for (int j=1, t; j<i; ++j) {
            t=Tower[i][j];
            Tower[i][j]=max(Tower[i-1][j-1], Tower[i-1][j])+t;
        }
    }
    int res=0;
    for (int i=0, t=n-1; i<n; ++i) if (Tower[t][i]>res) res=Tower[t][i];
    printf("%d\n", res);
    return 0;
}
